package com.minesweeper.tools;

import com.minesweeper.data.ImagesData;
import com.minesweeper.ui.GameInterface;

import javax.swing.*;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * @author skniy
 */
public class GameStatusListener implements MouseListener {

    /**
     * 游戏状态
     */
    private JLabel gameStatus;
    /**
     * 主面板
     */
    private GameInterface gameInterface;

    /**
     * 构造方法
     *
     * @param gameStatus
     * @param gameInterface
     */
    public GameStatusListener(JLabel gameStatus, GameInterface gameInterface) {
        this.gameStatus = gameStatus;
        this.gameInterface = gameInterface;
    }

    @Override
    public void mousePressed(MouseEvent e) {
        //如果鼠标左键按下
        if (e.getModifiers() == InputEvent.BUTTON1_MASK) {
            gameStatus.setIcon(ImagesData.ICON_GAME_STATUS_NOTHING_PRESSED);
            gameInterface.getTimer().stop();
        }
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        //如果鼠标左键松开
        if (e.getModifiers() == InputEvent.BUTTON1_MASK) {
            gameInterface.restartGame();
        }
    }

    @Override
    public void mouseClicked(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }

    public JLabel getterGameStatus() {
        return gameStatus;
    }
}
